<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body style="display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh">
    <form>
        <label for="email">邮箱</label>
        <br>
        <input type="text" name="email" id="email">
        <br>
        <label for="password">密码</label>
        <br>
        <input type="password" name="password" id="password">
        <br>
        <button type="submit">
            登录
        </button>
    </form>
    <script>
        let msg = [{
            name: '张三',
            age: 20,
            strengths: 'JavaScript',
            avatar: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.39mOMBjUfsK-HL9jUbv1MwHaE7?pid=ImgDet&rs=1',
            email: 'yunding@qq.com',
            password: "" + 33333
        },
        {
            name: '李四',
            age: 19,
            strengths: 'python',
            avatar: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.YlKimVo94OkaZDZCzPIDpAHaFh?pid=ImgDet&rs=1',
            email: '12345678@163.com',
            password: "" + 11111
        },
        {
            name: '王五',
            age: 18,
            strengths: 'Java',
            avatar: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.P2hK9SRjhFE8WM9N8tgWFAHaEQ?pid=ImgDet&rs=1',
            email: 'yundingshuyuan@qq.cn',
            password: "" + 222222
        },
        ]
        document.querySelector('form').addEventListener('submit', e => {
            e.preventDefault()
            var user = new Object()
            user.email = "" + document.getElementById('email').value
            user.password = "" + document.getElementById('password').value

            var re = /^[a-zA-Z0-9_-]+@(qq|163)\.(com|cn)$/
            var result = re.test(user.email)
            console.log(result)
            if (result === false)
                alert("Email error")
            else {
                logon(user)
            }
        })
        function logon(user) {
            var i;
            for (i = 0; i < msg.length; i++) {
                if (user.email === msg[i].email && user.password === msg[i].password) {
                    console.log(i)
                    console.log(msg[i])
                    localStorage.obj = (JSON.stringify(msg[i]))
                    window.location.href = 'zuoye3.html'
                    break
                }
                else if (user.email === msg[i].email && user.password !== msg[i].password) {
                    alert("password error!")
                    break
                }
                else
                    if (i == msg.length - 1)
                        alert("input error")

            }
        }


    </script>
</body>

</html>